package id.pratama.soiscene;

import id.pratama.soiscene.config.IApps_Data;
import id.pratama.soiscene.config.IApps_Define;

import org.andengine.engine.camera.Camera;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.scene.Scene;
import org.andengine.opengl.font.Font;
import org.andengine.opengl.font.FontFactory;
import org.andengine.ui.activity.BaseGameActivity;
import org.andengine.ui.activity.SimpleBaseGameActivity;

import android.graphics.Typeface;
import android.view.KeyEvent;

public class MainActivity extends SimpleBaseGameActivity implements IApps_Data, IApps_Define
{
	public static BaseGameActivity	activity;

	private Camera					camera;
	private SceneManager			sm;
	public static Font				mFont;

	@Override
	public EngineOptions onCreateEngineOptions()
	{
		// TODO Auto-generated method stub
		activity = this;
		camera = new Camera(0, 0, RES_WIDTH, RES_HEIGHT);
		EngineOptions en = new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(
				RES_WIDTH, RES_HEIGHT), camera);
		en.getAudioOptions().setNeedsSound(true);
		return en;
	}

	@Override
	protected void onCreateResources()
	{
		// TODO Auto-generated method stub
		mFont = FontFactory.create(getFontManager(), getTextureManager(), 256, 256,
				Typeface.create(Typeface.DEFAULT, Typeface.BOLD), Utils.getRatio(50));
		mFont.load();

	}

	@Override
	protected Scene onCreateScene()
	{
		// TODO Auto-generated method stub
		sm = new SceneManager(activity);
		sm.setScene(SceneManager.SCENE_LOGO);
		return SceneManager.loadedScene;
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event)
	{
		// TODO Auto-generated method stub
		if (keyCode == KeyEvent.KEYCODE_BACK)
		{
			switch (SceneManager.currentScene)
			{
				case SceneManager.SCENE_ALATMUSIK:
					sm.setScene(SceneManager.SCENE_MENU);
					break;
				case SceneManager.SCENE_MENU:
					finish();
					break;
				case SceneManager.SCENE_PLAYING:
					sm.setScene(SceneManager.SCENE_ALATMUSIK);
					break;
			}
		}
		return false;
	}

}
